package IHM;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.LayoutStyle;

import IHM.ChoixJeux;
import IHM.GUI;

public class PPrincipal extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JButton bQuit;
	private JButton bSolo;
	private JButton bMulti;
	private GUI gui;
	
	public PPrincipal(GUI gui) {
		
		super();
		this.gui=gui;
		initGUI();
	}
	
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)this);
			this.setLayout(thisLayout);
			this.setSize(784, 533);
			this.setPreferredSize(new java.awt.Dimension(784, 533));
			{
				bQuit = new JButton();
				bQuit.setName("bQuit");
				bQuit.setText("Quitter");
				bQuit.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.exit(0);
					}
				});
			}
			{
				bSolo = new JButton();
				bSolo.setName("bSolo");
				bSolo.setText("Jouer en Solo");
				bSolo.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						bSoloActionPerformed(evt);
					}
				});
			}
			{
				bMulti = new JButton();
				bMulti.setName("bMulti");
				bMulti.setText("Jouer en Multi");
				bMulti.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						bMultiActionPerformed(evt);
					}
				});
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(172, 172)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(bSolo, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE)
				        .addGap(6))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0, GroupLayout.PREFERRED_SIZE)
				        .addComponent(bMulti, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE)))
				.addGap(0, 168, GroupLayout.PREFERRED_SIZE)
				.addComponent(bQuit, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
				.addContainerGap(32, 32));
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(158, 158)
				.addComponent(bSolo, GroupLayout.PREFERRED_SIZE, 183, GroupLayout.PREFERRED_SIZE)
				.addGap(0, 97, Short.MAX_VALUE)
				.addComponent(bMulti, GroupLayout.PREFERRED_SIZE, 183, GroupLayout.PREFERRED_SIZE)
				.addGap(38)
				.addComponent(bQuit, GroupLayout.PREFERRED_SIZE, 82, GroupLayout.PREFERRED_SIZE)
				.addContainerGap(43, 43));
			//Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

    private void bSoloActionPerformed(ActionEvent evt) {
    	gui.change(new ChoixJeux(gui,true));
    }
    
    private void bMultiActionPerformed(ActionEvent evt) {
        JFrame parent = (JFrame) getParent();
        parent.getContentPane().remove(this);
        //parent.add(new PMulti(),BorderLayout.CENTER);
        parent.repaint();
    }

}
